package com.ruoyi.reservationserver.service.impl;

import com.ruoyi.reservationserver.dao.MembershiplevelsDao;
import com.ruoyi.reservationserver.entity.Membershiplevels;
import com.ruoyi.reservationserver.service.MembershiplevelsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * &会员级别制度
0-普通用户 无需买卡， 打球一次15元
1-月卡用户  买卡20元，打球一次12元
2-季卡用户 买卡50元，打球一次10元
3-年卡用户 买卡 160元，打球一次8元
(Membershiplevels)表服务实现类
 *
 * @author makejava
 * @since 2023-07-04 16:21:49
 */
@Service("membershiplevelsService")
public class MembershiplevelsServiceImpl implements MembershiplevelsService {
    @Resource
    private MembershiplevelsDao membershiplevelsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param levelId 主键
     * @return 实例对象
     */
    @Override
    public Membershiplevels queryById(Integer levelId) {
        return this.membershiplevelsDao.queryById(levelId);
    }

    /**
     * 分页查询
     *
     * @param membershiplevels 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Membershiplevels> queryByPage(Membershiplevels membershiplevels, PageRequest pageRequest) {
        long total = this.membershiplevelsDao.count(membershiplevels);
        return new PageImpl<>(this.membershiplevelsDao.queryAllByLimit(membershiplevels, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param membershiplevels 实例对象
     * @return 实例对象
     */
    @Override
    public Membershiplevels insert(Membershiplevels membershiplevels) {
        this.membershiplevelsDao.insert(membershiplevels);
        return membershiplevels;
    }

    /**
     * 修改数据
     *
     * @param membershiplevels 实例对象
     * @return 实例对象
     */
    @Override
    public Membershiplevels update(Membershiplevels membershiplevels) {
        this.membershiplevelsDao.update(membershiplevels);
        return this.queryById(membershiplevels.getLevelId());
    }

    /**
     * 通过主键删除数据
     *
     * @param levelId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer levelId) {
        return this.membershiplevelsDao.deleteById(levelId) > 0;
    }
}
